package com.qf.context;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
杨威
2021/9/13
19:52
*/
@WebServlet("/app")
public class ApplicationServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext = req.getServletContext();
        //获取真实路径
        String realPath = servletContext.getRealPath("/");
        //获取相对路径
        String contextPath = servletContext.getContextPath();
        //request获取相对路径  推荐
        String contextPath1 = req.getContextPath();
        //打印
        System.out.println(realPath);
        System.out.println(contextPath);
        System.out.println(contextPath1);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
